<?php

class Data {

	private $data;
	private $tipo;

	public function __construct( $data ) {
		$this->data = $data;
		if ( preg_match("/(....)-(..)-(..)/", $data ) )
			$this->tipo = 0;
		else 
			$this->tipo = 1;
	}

	public function formataDataBanco() {
			$this->data = preg_replace("/(..)\/(..)\/(....)/","$3-$2-$1", $this->data );
	}

	public function formataDataBr() {
			$this->data = preg_replace("/(....)-(..)-(..)/","$3/$2/$1", $this->data );
	}

	public function isValid() {

		if ( $this->tipo )
			$this->formataDataBanco();

		$banco = Database::getBanco();
		$row = $banco->query("SELECT DATE('" . $this->data . "') AS valid ");
		$row = $row->fetch_object();

		if ( $row->valid )
			return true;

	}

}

?>